<?php
require_once('config.inc.php');

$dbname = DB_NAME;

if(!@$title = $_POST["title"])
		$title = '';
if(!@$firstname = $_POST["firstname"])
		$firstname = '';
if(!@$lastname = $_POST["lastname"])
		$lastname = '';
if(!@$postcode = $_POST["postcode"])
		$postcode = '';
if(!@$city = $_POST["city"])
		$city = '';
if(!@$country = $_POST["country"])
		$country = '';
if(!@$address = $_POST["address"])
		$address = '';
if(!@$phone = $_POST["phone"])
		$phone = '';
if(!@$position = $_POST["position"])
		$position = '';
if(!@$employer = $_POST["employer"])
		$employer = '';
if(!@$mail = $_POST["mail"])
		$mail = '';
if(!@$homepage = $_POST["homepage"])
		$homepage = '';
$user_id = $_GET["user_id"];

/* make connection to database */
MYSQL_CONNECT(DB_SERVER,DB_USER_NAME,DB_USER_PASSWORD) OR DIE("Could not create database-connection!");
@mysql_select_db("$dbname") or die("Database not found!"); 

class EditUserData
{
	function edit($firstname, $lastname, $address, $postcode, $city, $country, $phone, $employer, $mail, $title, $homepage, $position, $user_id)
	{
		/* MySQL table created to store the data */
		$tablename = "userdata";
		
		/* Insert information into table */
		$query = "UPDATE $tablename SET firstname='$firstname', lastname='$lastname', address='$address', postcode=$postcode, city='$city', country='$country', phone='$phone', employer='$employer', mail='$mail', title='$title', homepage='$homepage', position='$position' WHERE user_id='$user_id'";
		$result = MYSQL_QUERY($query);
		
		if(!$result)
			header("Location: errorpage.php?error=query_failed");
	}
}

$userdata = new editUserData();
$userdata->edit($firstname, $lastname, $address, $postcode, $city, $country, $phone, $employer, $mail, $title, $homepage, $position, $user_id);

include("index.php");

/* Close the database connection */
MYSQL_CLOSE();
?>